<?php
// 创建计划任务脚本
class CleanLogs {
    public function execute() {
        $db = \PhalApi\DI()->notorm->phone_log;
        
        // 获取所有不同的oaid
        $oaids = $db->select('DISTINCT oaid')->fetchAll();
        
        foreach ($oaids as $row) {
            $oaid = $row['oaid'];
            
            // 获取第10000条记录的时间
            $oldestAllowed = $db->where('oaid', $oaid)
                               ->order('create_time DESC')
                               ->limit(1)
                               ->offset(9999)
                               ->fetchOne();
                               
            if ($oldestAllowed) {
                // 删除更老的记录
                $db->where('oaid', $oaid)
                   ->where('create_time < ?', $oldestAllowed['create_time'])
                   ->delete();
            }
        }
    }
} 